/*
 * @Author: Kang
 * @Date: 2023-08-29 11:04:54
 * @Last Modified by: Kang
 * @LastEditTime: 2023-08-29 15:41:43
 */
import { Controller, Get, Query, ValidationPipe } from '@nestjs/common';
import { FileReadService } from './file-read.service';
import * as fs from 'fs';

@Controller('api')
export class FileReadController {
  constructor(private readonly fileReadService: FileReadService) {}
  @Get('/fileRead')
  async getFileRead(): Promise<any> {
    try {
      //转换svg为utf-8格式
      let svgContent = await fs.promises.readFile(
        'src/assets/images/cert.svg',
        'utf-8',
      );
      //替换空位的变量的值，这些值正常是根据前端传参查出指定的用户信息赋值替换上去的
      svgContent = svgContent.replace(/namenamename/gi, '张三');
      svgContent = svgContent.replace(/IDIDIDIDIDIDIDIDI/gi, '1234567789090');
      svgContent = svgContent.replace(/certCERTCERTCERT/gi, '1234567890123');
      svgContent = svgContent.replace(/timeTIMTIMTIMTI/gi, '2023-08-29');
      return svgContent;
    } catch (error) {
      return error;
    }
  }
}
